public class BinarySearchTree {
    public static class TreeNode{
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public TreeNode root = null;
    public boolean insert(int val){
        TreeNode r = new TreeNode(val);
        if(root == null){
            root = r;
            return true;
        }
        TreeNode p = null;
        TreeNode cur = root;
        while(cur != null){
            p = cur;
            if(cur.val > val){
                cur = cur.left;
            }else if(cur.val < val){
                cur = cur.right;
            }else{
                return false;
            }
        }
        if(p.val > val){
            p.left = r;
        }else{
            p.right = r;
        }
        return true;
    }
}
